home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-13 | 21.1 KB | 632 lines | [TEXT/ds30] |
- /*
- P.INK SQL DataServer configuration
- --------------------------------------
-
- Procedure CONFIG
-
- This procedure calculates values for system variables
- for 'good performance operation' of a DataServer.
- There are several input parameters for configuration
- which will be described when the procedure is called
- from a console like this:
- config(1);
-
- If you just want to have a look at some examples:
- config(2);
-
- For credits:
- config(6);
-
- P.INK Hamburg, October 1993 (updated September 1995)
-
- */
-
- declare procedure config(CheckTotalMemory, NumberOfSessions, System, SetVar)
- argument int CheckTotalMemory = 0;
- argument int NumberOfSessions = 0;
- argument int System = 0;
- argument char SetVar = "NO";
- {
- int StaticMemory = 1536;
- int MaxStaticMemory = 3074;
- int ServerFrontEnd;
- int LogBufferSize = 2 * 32;
- int InitialMemoryBlock, Sessions, SessionSize = 256;
- int TotalMemory, RestMemory, CacheMemory, ConnectionMemory, BlockSize, BlockCount, UsedMemory;
- int SystemFiles, TransactionLimit;
- int cVersion = integer($substr($right($version, '#'), 1, 4));
-
- int is_open = 0;
- varchar dname = "<unknown>";
- varchar cSystem;
-
- print "";
-
- if(CheckTotalMemory != 5)
- {
- print $format("\tP.INK SQL DataServer configuration");
- print $format("\t--------------------------------------");
- }
-
- if(CheckTotalMemory < 0 or NumberOfSessions < 0 or (CheckTotalMemory > 6 and CheckTotalMemory < 2048))
- {
- print $format("\tInvalid input parameter !");
- CheckTotalMemory = 1;
- print "";
- }
-
- SetVar = $toupper(SetVar);
- if(System < 0 or System > 2)
- System = 0;
-
- if(CheckTotalMemory = 1)
- {
- print $format("\tThis procedure CONFIG calculates a configuration that");
- print $format("\tshould give 'good performance' in common environments.");
- print "";
- print $format("\tFor good performance the memory that is available to the server");
- print $format("\tis reduced by the amount of static memory and then split to 1/3");
- print $format("\tfor Session memory and 2/3 for Cache and Virtual Cache memory.");
- print $format("\tIf there is not enough memory available, the required size per session");
- print $format("\tis reduced from 256 KB to 128 KB. If there is still not enough memory");
- print $format("\tavailable the required size for the Cache and Virtual Cache is reduced");
- print $format("\tdown to a limit of 512 KB. If there is still not enough memory the");
- print $format("\tlast thing to do is to reduce the number of sessions.");
- print "";
- print $format('\tCall the procedure like this:');
- print $format('\tCONFIG(Memory, Sessions, System, "Set");');
- print "";
- print $format("\tMemory : 0 or empty calculates required memory for the current server.");
- print $format("\t 1 shows this information.");
- print $format('\t 2 shows examples of how to call this procedure.');
- print $format('\t 3 shows the current values of the system variables on current Server.');
- print $format('\t 4 same as 3 plus other system variables and system formats.');
- print $format("\t Any number greater than 2048 is the considered to be the number");
- print $format("\t of KB of memory you want to give to the DataServer.");
- print "";
- print $format("\tSessions: Number of Sessions you want to give to the DataServer.");
- print $format("\t 0 or empty caluclates with the value of ConnectionLimit.");
- print "";
- print $format('\tSystem : 1 calculation is for a Macintosh server.');
- print $format('\t 2 calculation is for a Unix server.');
- print $format("\t 0 or empty calculates for the current server.");
- print "";
- print $format('\tSet : "save" if you are satisfied with the calculated values and');
- print $format("\t you want the procedure to save them on the DataServer.");
- print $format('\t "show" preceeds the calculated values with SET VARIABLE');
- print $format("\t so they can be used with copy/paste to save them 'by hand'.");
- print "";
- print $format('\tCall CONFIG(1) for this information or CONFIG(2) for examples.');
- print "";
- return;
- }
- if(CheckTotalMemory = 2)
- {
- print $format("\tExamples:");
- print $format("\tconfig(1);");
- print $format("\tShow help information about this procedure.");
- print "";
- print $format("\tconfig(3);");
- print $format('\tShow the current values of the system variables on current Server.');
- print "";
- print $format('\tconfig(4,,,"show"); OR setting;');
- print $format('\tShow current values of the system variables and formats with SET VARIABLE.');
- print "";
- print $format("\tconfig; or config(0,0,0,0);");
- print $format("\tCalculate required memory for current Server with current sessions.");
- print "";
- print $format('\tconfig(16*1024, ,2);');
- print $format('\tShow values for a Unix Server with current sessions and 16 MB.');
- print "";
- print $format('\tconfig(5*1024, 10, 1);');
- print $format('\tShow values for a Mac Server with 5 MB and 20 sessions.');
- print "";
- print $format('\tconfig(,10,, "save");');
- print $format('\tCalculate required memory for 10 sessions on current Server and save values.');
- print "";
- print $format('\tconfig(4500, 10, 1, "show");');
- print $format('\tShow values with SET VARIABLE for a Mac Server with 4500 KB and 10 sessions.');
- print "";
- return;
- }
-
- if(CheckTotalMemory = 6)
- {
- print $format("\tThis procedure 'CONFIG' (version 1.6) was brought to you by:");
- print "";
- print $format("\tDAL programming:\tDieko Jacobi");
- print $format("\tMemory manager :\tPaul McCullagh");
- print $format("\tSpecial thanks :\tMitch Frazer, Dirk Strack, Ingo Karge, Barry Leslie");
- print "";
- print $format("\tP.INK software engineering GmbH & Co.");
- print $format("\tRothenbaumchaussee 5");
- print $format("\t20148 Hamburg");
- print $format("\tGermany");
- print "";
- print $format("\tFor further information call: ++49 - 40 - 411 709 0");
- print $format("\t Fax: ++49 - 40 - 411 709 10");
- print $format("\t Internet: support.sql@pink.de");
- print $format("\t Apple Link: Ger.XSE0006");
- print "";
- print "";
- print "";
- return;
- }
-
- describe open databases into db;
- for each db
- {
- if(db->alias = "mem_set")
- {
- is_open = 1;
- use database mem_set;
- break;
- }
- }
-
- if(is_open=0)
- {
- errorctl ,1;
- open database master alias mem_set;
- errorctl ,0;
-
- describe open databases into db;
- for each db
- {
- if(db->alias = "mem_set")
- {
- is_open = 1;
- break;
- }
- }
- }
-
- if(CheckTotalMemory = 3 or CheckTotalMemory = 4 or CheckTotalMemory = 5)
- {
- if(is_open=0)
- {
- print $format("\tThe Master database is not open so the values");
- print $format("\tof the system variables can not be looked up.");
- print $format("\tYou need SA privilege to open the Master database.");
- print "";
- return;
- }
- /* DataServerName */
- select value
- from sysvariables
- where id = (select id from SysObjects where Name = "DataServerName")
- into tmp for extract;
- fetch first of tmp;
- dname = tmp->value;
- print $format("\tCurrent values of the system variables on DataServer '%s':", dname);
-
- select B.Name, int A.Value as Value, A.DBID
- from mem_set!System.SysVariables as A,
- mem_set!System.SysObjects as B
- where A.DBID /= B.DBID
- and A.DataType == $integer
- and A.VariableType == 'Par'
- order by A.DBID
- into vars;
- for each vars
- {
- if (not ($locate(vars->Name, "Memory") > 0 and vars->Value is null))
- {
- if(SetVar = "SHOW")
- print $format("\tSET VARIABLE %-25s = %d;", vars->Name, vars->Value);
- else
- {
- if(vars->Value > 1024)
- print $format("\t%-25s = %-10s (%d KB)", vars->Name, vars->Value, vars->Value / 1024);
- else
- print $format("\t%-25s = %d", vars->Name, vars->Value);
- }
- }
- }
-
- if(CheckTotalMemory = 3)
- {
- print "";
- print $format('\tTry also:');
- print $format('\tCONFIG(4,,,"show");');
- print $format('\tor');
- print $format('\tSETTING;');
- }
-
- if(CheckTotalMemory = 4)
- {
- select B.Name, varchar A.Value as Value, A.DBID
- from mem_set!System.SysVariables as A,
- mem_set!System.SysObjects as B
- where A.DBID /= B.DBID
- and A.DataType == $varchar
- and A.VariableType == 'Par'
- order by A.DBID
- into vars;
- for each vars
- {
- if(SetVar = "SHOW")
- print $format("\tSET VARIABLE %-25s = '%s';", vars->Name, vars->Value);
- else
- print $format("\t%-25s = %s", vars->Name, vars->Value);
- }
- print "";
- if(SetVar = "SHOW")
- {
- print $format("\tLimits:");
- print $format("\tSET $maxrows = %d;", $maxrows);
- print $format("\tSET $rowsperpage = %d;", $rowsperpage);
- print $format("\tSET $locktimeout = %d;", $locktimeout);
- print "";
-
- print $format("\tFormats:");
- print $format('\tSET $decfmt = "%s";', $decfmt);
- print $format('\tSET $moneyfmt = "%s";', $moneyfmt);
- print $format('\tSET $tsfmt = "%s";', $tsfmt);
- print $format('\tSET $datefmt = "%s";', $datefmt);
- print $format('\tSET $timefmt = "%s";', $timefmt);
- print $format('\tSET $month = "%s";', $month);
- print $format('\tSET $day = "%s";', $day);
- print $format('\tSET $ampm = "%s";', $ampm);
- print "";
- describe open dbms into vars;
- fetch of vars;
- print $format('\tYou are logged in as user "' + $user + '" using brand "' + vars->brand + '" version "' + vars->rev + '"');
- }
- else
- {
- print $format("\tLimits:");
- print $format("\t$maxrows = %d", $maxrows);
- print $format("\t$rowsperpage = %d", $rowsperpage);
- print $format("\t$locktimeout = %d", $locktimeout);
- print "";
-
- print $format("\tFormats:");
- print $format('\t$decfmt = %s', $decfmt);
- print $format('\t$moneyfmt = %s', $moneyfmt);
- print $format('\t$tsfmt = %s', $tsfmt);
- print $format('\t$datefmt = %s', $datefmt);
- print $format('\t$timefmt = %s', $timefmt);
- print $format('\t$month = %s', $month);
- print $format('\t$day = %s', $day);
- print $format('\t$ampm = %s', $ampm);
- print "";
- print $format('\tTry also:');
- print $format('\tCONFIG(4,,,"show");');
- print $format('\tor');
- print $format('\tSETTING;');
- }
- }
- print "";
- return;
- }
-
- if(System = 0)
- {
- if(is_open=0)
- {
- print $format("\tYou did not specify the system on what the DataServer is running");
- print $format("\tand the Master database is not open so it can not be looked up.");
- print $format('\tYou need SA privilege to open the Master database or call config(1);');
- print $format("\tfor further descriptions.");
- print "";
- return;
- }
- /* Get the SerialNumber */
- select value
- from sysvariables
- where id = (select id from SysObjects where Name = "SerialNumber")
- into tmp for extract;
- fetch first of tmp;
-
- /* The second digit contains version information: M = Mac, S/I = Unix, A = Any (ask) */
- if($substr(tmp->value,2,1) = "M")
- System = 1;
- if($substr(tmp->value,2,1) = "S" or $substr(tmp->value,2,1) = "I")
- System = 2;
-
- }
-
- if(System = 2)
- {
- cSystem = "Unix";
- ServerFrontEnd = 0;
- BlockSize = 1024;
- SystemFiles = 50;
- }
- else
- {
- if(System != 1)
- {
- print $format("\tThe system on what the DataServer is running can not be identified.");
- print $format('\tIf running on a Mac the 3. paramter has to be 1 on Unix 2');
- print $format('\tFor now the calculation will be continued for a Macintosh.');
- print $format('\tType: config(1); if you need more information about this procedure.');
- print $format('\tType: config(2); if you need examples of how to call this procedure.');
- print "";
- }
- cSystem = "Macintosh";
- ServerFrontEnd = 850;
- BlockSize = 512;
- SystemFiles = 240;
- }
-
- if(is_open=1)
- {
- /* DataServerName */
- select value
- from sysvariables
- where id = (select id from SysObjects where Name = "DataServerName")
- into tmp for extract;
- fetch first of tmp;
- dname = tmp->value;
-
- /* LogBufferSize */
- select value
- from sysvariables
- where id = (select id from SysObjects where Name = "LogBufferSize")
- into tmp for extract;
- fetch first of tmp;
- LogBufferSize = 2 * (tmp->value / 1024);
- }
-
- StaticMemory = StaticMemory + LogBufferSize;
- if(StaticMemory > MaxStaticMemory)
- StaticMemory = MaxStaticMemory;
-
- if(is_open=1)
- print $format("\tTunings for the DataServer '%s' (%s)", dname, cSystem);
- else
- print $format("\tTunings for a DataServer running on %s", cSystem);
-
- print "";
- if(NumberOfSessions = 0)
- {
- if(is_open=0)
- {
- print $format("\tYou did not specify the number of sessions and");
- print $format("\tthe Master database is not open so it can not be looked up.");
- print $format("\tYou need SA privilege to open the Master database.");
- print $format("\tThe calculation will be based on the default value of 5 sessions.");
- print "";
- Sessions = 5;
- }
- else
- {
- /* ConnectionLimit */
- select value
- from sysvariables
- where id = (select id from SysObjects where Name = "ConnectionLimit")
- into tmp for extract;
- fetch first of tmp;
- Sessions = tmp->value;
- }
- }
- else
- Sessions = NumberOfSessions;
-
- ConnectionMemory = Sessions * SessionSize;
- CacheMemory = 2 * ConnectionMemory;
- TotalMemory = StaticMemory + ServerFrontEnd + CacheMemory + ConnectionMemory;
-
- print $format("\tGood performance with %d sessions requires %d KB of memory.", Sessions, TotalMemory);
-
- if(CheckTotalMemory > 0)
- {
- print $format("\tYou specified %d KB of memory for the calculation.", CheckTotalMemory);
- if(CheckTotalMemory = TotalMemory)
- print $format("\tThat is just right", CheckTotalMemory);
- else
- {
- print $format("\tGood performance with %d KB of memory supports %d sessions", CheckTotalMemory, ((CheckTotalMemory - ServerFrontEnd - StaticMemory) / 3) / SessionSize);
- while(TotalMemory > CheckTotalMemory and SessionSize > 128)
- {
- SessionSize = SessionSize -64;
- print $format('\tNot enough memory for %d KB per session, size reduced to %d KB', SessionSize +64, SessionSize);
- ConnectionMemory = Sessions * SessionSize;
- CacheMemory = 2 * ConnectionMemory;
- TotalMemory = StaticMemory + ServerFrontEnd + CacheMemory + ConnectionMemory;
- }
-
- if(TotalMemory < CheckTotalMemory)
- {
- print $format("\tThere are %d KB more than required which will be added to the Cache memory.", CheckTotalMemory - TotalMemory);
- CacheMemory = CacheMemory + (CheckTotalMemory - TotalMemory);
- TotalMemory = StaticMemory + ServerFrontEnd + CacheMemory + ConnectionMemory;
- }
- else
- {
- if(TotalMemory > CheckTotalMemory)
- {
- print $format('\tNot enough memory for minimum connection size, reducing cache size');
- CacheMemory = 2 * ConnectionMemory;
-
- /* Reduce cache size in steps of 10% */
- while(ServerFrontEnd + CacheMemory + ConnectionMemory + StaticMemory > CheckTotalMemory and CacheMemory >= 512)
- CacheMemory = CacheMemory - (CacheMemory / 10);
-
- if(ServerFrontEnd + CacheMemory + ConnectionMemory + StaticMemory <= CheckTotalMemory)
- CacheMemory = CacheMemory + CheckTotalMemory - (ServerFrontEnd + CacheMemory + ConnectionMemory + StaticMemory);
- TotalMemory = StaticMemory + ServerFrontEnd + CacheMemory + ConnectionMemory;
- print $format('\tCache memory is reduced to %d KB (%d%)', CacheMemory, (CacheMemory+0.0) * 100 / (TotalMemory - ServerFrontEnd - StaticMemory));
- }
- else
- {
- CacheMemory = CacheMemory + (CheckTotalMemory - TotalMemory);
- TotalMemory = StaticMemory + ServerFrontEnd + CacheMemory + ConnectionMemory;
- }
- if(TotalMemory > CheckTotalMemory)
- {
- print $format('\tBut even this minimum configuration for %d sessions requires %d KB', Sessions, TotalMemory);
- Sessions = (2 * ((CheckTotalMemory - ServerFrontEnd - StaticMemory) / 3) / 128);
- print $format('\tThe configuration with %d KB should not have more than %d sessions', CheckTotalMemory, Sessions);
- print "";
- return;
- }
- else
- {
- CacheMemory = CacheMemory + (CheckTotalMemory - TotalMemory);
- TotalMemory = StaticMemory + ServerFrontEnd + CacheMemory + ConnectionMemory;
- }
-
- print $format('\t%d KB supports %d sessions (%d KB) with reduced cache memory', TotalMemory, Sessions, SessionSize);
- print $format("\tThat is OK");
- }
- }
- }
- if(CacheMemory < 512)
- {
- print $format("\tBut: Not enough memory for Cache: Minimum is 512 KB, available are %d KB", CacheMemory);
- print "";
- return;
- }
-
- /* Take 25 % of the available memory for the InitialMemoryBlock */
- InitialMemoryBlock = TotalMemory/4;
-
- RestMemory = TotalMemory - InitialMemoryBlock;
- BlockCount = (RestMemory / BlockSize) +1;
-
- if( BlockCount > 40)
- {
- BlockCount = 40;
- BlockSize = RestMemory / (BlockCount - 1);
- }
-
- while(BlockCount < 2)
- {
- BlockSize = BlockSize / 2;
- print $format("\tNot enough blocks (%d) available, block size reduced from %d KB to %d KB", BlockCount, BlockSize*2, BlockSize);
- BlockCount = (RestMemory / BlockSize) +1;
- }
- UsedMemory = ((BlockCount -1) * BlockSize);
-
- /* Add the rest of the block memory to the InitialMemoryBlock */
- InitialMemoryBlock = InitialMemoryBlock + (RestMemory - UsedMemory);
-
- print "";
- print $format("\tThe memory is used like this:");
- if(cSystem = "Macintosh")
- print $format("\tDataServer frontend \t\t=%8d KB", ServerFrontEnd);
- print $format("\tStatic Memory \t\t=%8d KB", StaticMemory);
- print $format("\t%d Sessions (%d KB each)\t=%8d KB (%d\%)", Sessions, SessionSize, ConnectionMemory, (ConnectionMemory+0.0) *100 / (TotalMemory - ServerFrontEnd - StaticMemory));
- print $format("\tCache Memory \t\t=%8d KB (%d\%)", CacheMemory, (CacheMemory+0.0) *100 / (TotalMemory - ServerFrontEnd - StaticMemory));
- print $format("\t \t\t------------");
- print $format("\tTotal \t\t=%8d KB", StaticMemory + ServerFrontEnd + CacheMemory + ConnectionMemory);
-
- print "";
- TransactionLimit = Sessions;
- if(Sessions < 32)
- TransactionLimit = 31;
- if(Sessions > 255)
- TransactionLimit = 254;
-
- if(SetVar = "SAVE")
- print $format("\tThe system variables will be set to the following values:");
- else
- print $format("\tThe system variables should be set to the following values:");
-
- if(SetVar = "SHOW")
- {
- print $format("\tSET VARIABLE %-25s = %d;", "TransactionLimit", TransactionLimit + 1);
- print $format("\tSET VARIABLE %-25s = %d;", "SystemFileLimit", SystemFiles);
- print $format("\tSET VARIABLE %-25s = %d;", "CacheSize", CacheMemory/2 * 1024);
- print $format("\tSET VARIABLE %-25s = %d;", "VirtualCacheSize", CacheMemory/2 * 1024);
- print $format("\tSET VARIABLE %-25s = %d;", "ConnectionLimit", Sessions);
- if (not (cSystem = "Macintosh" and cVersion >= 2400))
- {
- print $format("\tSET VARIABLE %-25s = %d;", "InitialMemoryBlockSize", InitialMemoryBlock * 1024);
- print $format("\tSET VARIABLE %-25s = %d;", "MemoryBlockSize", BlockSize * 1024);
- print $format("\tSET VARIABLE %-25s = %d;", "MemoryBlockTotal", BlockCount);
- }
- config(5,,,"show");
- }
- else
- {
- print $format("\tTransactionLimit = %d", TransactionLimit + 1);
- print $format("\tSystemFileLimit = %d", SystemFiles);
- print $format("\tCacheSize = %d", CacheMemory/2 * 1024);
- print $format("\tVirtualCacheSize = %d", CacheMemory/2 * 1024);
- print $format("\tConnectionLimit = %d", Sessions);
- if (not (cSystem = "Macintosh" and cVersion >= 2400))
- {
- print $format("\tInitialMemoryBlockSize = %d", InitialMemoryBlock * 1024);
- print $format("\tMemoryBlockSize = %d", BlockSize * 1024);
- print $format("\tMemoryBlockTotal = %d", BlockCount);
- }
- }
- print "";
-
- if(SetVar = "SAVE")
- {
- if(is_open=0)
- {
- print $format("\tThe Master database is not open so the values");
- print $format("\tof the system variables can not be saved.");
- print $format("\tYou need SA privilege to open the Master database.");
- print "";
- return;
- }
-
- /* ConnectionTotal */
- select value
- from sysvariables
- where id = (select id from SysObjects where Name = "ConnectionTotal")
- into tmp for extract;
-
- if($rows(tmp) == 1)
- {
- fetch first of tmp;
-
- if(Sessions > tmp->value)
- {
- print $format("\tThe values can not be saved because the calculation is based on");
- print $format("\t%d sessions but the DataServer has a limit of %d sessions.", Sessions, int tmp->value);
- print "";
- return;
- }
- }
- print $format("\tSaving the system variables...");
- SET VARIABLE ConnectionLimit = Sessions;
- SET VARIABLE CacheSize = CacheMemory/2 * 1024;
- SET VARIABLE VirtualCacheSize = CacheMemory/2 * 1024;
- SET VARIABLE TransactionLimit = TransactionLimit + 1;
- SET VARIABLE SystemFileLimit = SystemFiles;
- if (cSystem = "Macintosh" and cVersion >= 2400)
- {
- SET VARIABLE InitialMemoryBlockSize = $null;
- SET VARIABLE MemoryBlockTotal = $null;
- SET VARIABLE MemoryBlockSize = $null;
- }
- else
- {
- SET VARIABLE InitialMemoryBlockSize = InitialMemoryBlock * 1024;
- SET VARIABLE MemoryBlockTotal = BlockCount;
- SET VARIABLE MemoryBlockSize = BlockSize * 1024;
- }
- print $format("\tDone");
- if(cSystem = "Macintosh")
- {
- print $format("\tCaution: Set the 'Minimum size' in 'Memory Requirements' of the");
- print $format("\t Server application with the finder's 'Get info' to %d", TotalMemory);
- print "";
- }
- config(5);
- close database mem_set;
- }
- }
- end procedure config;
-
- procedure setting()
- {
- config(4,,,"show");
- }
- end procedure setting;
-
- config(1);
-
- /*
- execute file "config";
- go
- */
-